#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    FILE* file_ptr;
    file_ptr = fopen("bite","w");
    const char* str = "linux is ease!";
    size_t write = fwrite(str,sizeof(char),strlen(str),file_ptr);
    pclose(file_ptr);
    file_ptr = fopen("bite","r");
    char buffer[100];
    size_t resd = fread(buffer,sizeof(char),sizeof(buffer),file_ptr);
    printf("read string is : %s\n",buffer);
    pclose(file_ptr);
    return 0;
}
#include <string>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
    const char *str = "i love linux!";
    const char *file_name = "bite";
    char buffer[50];
    int fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC);

    ssize_t wt = write(fd, str, strlen(str));
    if (wt == -1) {
        perror("write");
        close(fd);
        return EXIT_FAILURE;
    }
    if (lseek(fd, 0, SEEK_SET) == -1)
    {
        perror("lseek");
        close(fd);
        return EXIT_FAILURE;
    }

    ssize_t rd = read(fd, buffer, sizeof(buffer) - 1);
    if (rd == -1)
    {
        perror("read");
        close(fd);
        return EXIT_FAILURE;
    }
    buffer[rd] = '\0';
    close(fd);
    printf("read str is : %s\n", buffer);
    return 0;
}
